--- sys/contrib/openzfs/module/zfs/btree.c.orig
+++ sys/contrib/openzfs/module/zfs/btree.c
@@ -1536,8 +1536,8 @@
 	zfs_btree_poison_node_at(tree, keep_hdr, keep_hdr->bth_count);
 
 	new_rm_hdr->bth_count = 0;
-	zfs_btree_node_destroy(tree, new_rm_hdr);
 	zfs_btree_remove_from_node(tree, parent, new_rm_hdr);
+	zfs_btree_node_destroy(tree, new_rm_hdr);
 }
 
 /* Remove the element at the specific location. */
@@ -1766,9 +1766,9 @@
 	zfs_btree_poison_node_at(tree, keep_hdr, keep_hdr->bth_count);
 
 	rm_hdr->bth_count = 0;
-	zfs_btree_node_destroy(tree, rm_hdr);
 	/* Remove the emptied node from the parent. */
 	zfs_btree_remove_from_node(tree, parent, rm_hdr);
+	zfs_btree_node_destroy(tree, rm_hdr);
 	zfs_btree_verify(tree);
 }
 
